﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YArchitech.Revit;
using YJKArchUtils.Utils;
using YJKRevitDimensionText.OneKeyPlanDim.Utility;

namespace YJKRevitDimensionText.OneKeyPlanDim.LevelDim.Data
{
	public class FloorGeometry
	{
		public FloorGeometry(Floor floor)
		{
			this.m_Floor = floor;
			if (floor != null)
			{
				Parameter parameter = RevitElementExtension.GetParameter(floor, BuiltInParameter.STRUCTURAL_ELEVATION_AT_TOP);
				if (parameter != null)
				{
					this.m_dLevelVal = parameter.AsDouble();
				}
				this.m_dLevelVal = Common.FeetToMM(this.m_dLevelVal) / 1000.0;
				this.m_strLevelVal = this.m_dLevelVal.ToString("f3");
				this.m_lstBaseCv = this.BasePlanarFaceCv(floor);
			}
		}

		private PlanarFace GetBasePlanarFace(Floor floor)
		{
			foreach (PlanarFace planarFace in GeometryHelper.GetAllPlanarFace(floor))
			{
				if (GeometryHelper.VectorParallelVector(XYZ.BasisZ, planarFace.FaceNormal))
				{
					return planarFace;
				}
			}
			return null;
		}

		private List<Curve> BasePlanarFaceCv(Floor floor)
		{
			List<Curve> list = new List<Curve>();
			this.m_planarFace = this.GetBasePlanarFace(floor);
			if (this.m_planarFace == null)
			{
				return list;
			}
			List<Curve> list2 = new List<Curve>();
			list = GeometryHelper.GetAllEdgeList(this.m_planarFace);
			foreach (Curve curve in list)
			{
				list2.Add(CommonInterface.GetXYPlaneCurve(curve));
			}
			return list2;
		}

		public Floor m_Floor;

		public PlanarFace m_planarFace;

		public List<Curve> m_lstBaseCv = new List<Curve>();

		public double m_dLevelVal;

		public string m_strLevelVal = string.Empty;
	}
}
